//202102104015柴亚楠
package cn.edu.sdjzu.xg.kcsj.controller;

import cn.edu.sdjzu.xg.kcsj.domain.StudentClass;
import cn.edu.sdjzu.xg.kcsj.service.StudentClassService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import util.JSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/updateStudentClass.ctl")
public class UpdateStudentClassController extends HttpServlet {
    @Override
    protected void doPost (HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException {
        JSONObject message = new JSONObject();
        String student_json = JSONUtil.getJSON(req);
        StudentClass studentClass = JSON.parseObject(student_json, StudentClass.class);
        try {
            if (StudentClassService.getInstance().update(studentClass)){
                message.put("message", "update yes");
            }else{
                message.put("message", "update no");
            }
        } catch (SQLException e) {
            message.put("message", "sjk have exception");
        } catch (Exception e) {
            message.put("message", "wl have exception");
        }
        resp.getWriter().println(message);
    }
}
